function showNetworkError() {
    wx.hideToast();
    wx.showToast({
        title: "网络异常，请重试"
    });
}

function convertStarsToStarsArray(stars) {
    var num = stars.substring(0, 1);
    var array = [];
    for (var i = 1; i <= 5; i++) {
        if (i <= num) {
            array.push(1);
        } else {
            array.push(0);
        }
    }
    return array;
}

function http(url, successCallback,failCallback) {
    var that = this;
    wx.request({
        url: url,
        method: 'GET',
        header: { "Content-Type": "json" },
        success: function (result) {
            if(successCallback)
                successCallback(result.data);
        },
        fail: function (res) {
            that.showNetworkError();
            if(failCallback)
                failCallback(res);
        }
    });
}


function showLoadingToast(){
     wx.showToast({
        title:"加载中",
        icon:"loading",
        mask:true,
        duration:10000
    });
}
module.exports.showNetworkError = showNetworkError;
module.exports.convertStarsToStarsArray = convertStarsToStarsArray;
module.exports.http = http;
module.exports.showLoadingToast = showLoadingToast;